import type { MenuDataItem } from '@umijs/route-utils';
import EditOutlined from '@/components/MenuIcon/EditOutlined';
export const serverRoutes = [
  {
      "name": "基础投放",
      "path": "/promotions",
     
      "routes": [
          {
              "name": "广告推广",
              "path": "advertising",
              "component": "./Advertising/Advertising"
          }
      ]
  },
  {
      "name": "素材中心",
      "path": "/source",
      "routes": [
          {
              "name": "视频管理",
              "path": "video",
              "component": "./Advertising/Advertising"
          },
          {
              "name": "素材库",
              "path": "materialCenter",
              "component": "./Advertising/Advertising"
          },
          {
              "name": "图片库",
              "path": "picture",
              "component": "./Advertising/Advertising"
          },
          {
              "name": "图文库",
              "path": "graphicLibrary",
              "component": "./Advertising/Advertising"
          },
          {
              "name": "标题库",
              "path": "copywriting",
              "component": "./Advertising/Advertising"
          },
          {
              "name": "落地页",
              "path": "landingpage",
              "component": "./Advertising/Advertising"
          },
          {
              "name": "原生锚点",
              "path": "anchorpoint",
              "component": "./Advertising/Advertising"
          },
          {
              "name": "视频池",
              "path": "videoPool",
              "component": "./Advertising/Advertising"
          }
      ]
  },
  {
      "name": "概览",
      "path": "/overview",
      "routes": [
          {
              "name": "统计概览",
              "path": "statistical",
              "component": "./Statistical/Statistical"
          }
      ]
  },
  {
      "name": "事件资产",
      "path": "/property",
      "routes": [
          {
              "name": "定向管理",
              "path": "directional",
              "component": "./Directional/Directional"
          },
          {
              "name": "产品库",
              "path": "product",
              "component": "./Product/Product"
          },
          {
              "name": "事件管理",
              "path": "event",
              "component": "./Event/Event"
          }
      ]
  },
  {
      "name": "工具",
      "path": "/tool",
      "routes": [
          {
              "name": "管控工具",
              "path": "management",
              "component": "./Management/Management"
          },
          {
              "name": "资金调拨",
              "path": "fundAllocation",
              "component": "./FundAllocation/FundAllocation"
          },
          {
              "name": "屏蔽规则",
              "path": "blockingRules",
              "component": "./BlockingRules/BlockingRules"
          },
          {
              "name": "评论管理",
              "path": "commentManagement",
              "component": "./CommentManagement/CommentManagement"
          },
          {
              "name": "筛选工具",
              "path": "adFilters",
              "component": "./AdFilters/AdFilters"
          }
      ]
  },
  {
      "name": "数据报表",
      "path": "/report",
      "routes": [
          {
              "name": "受众报表",
              "path": "analysis",
              "component": "./Analysis/Analysis"
          },
          {
              "name": "优化师报表",
              "path": "optimist",
              "component": "./Optimist/Optimist"
          },
          {
              "name": "品牌报表",
              "path": "brand",
              "component": "./Brand/Brand"
          },
          {
              "name": "渠道报表",
              "path": "channel",
              "component": "./Channel/Channel"
          },
          {
              "name": "定向包报表",
              "path": "audiencePackageReport",
              "component": "./AudiencePackageReport/AudiencePackageReport"
          },
          {
              "name": "账户报表",
              "path": "advReport",
              "component": "./AdvReport/AdvReport"
          },
          {
              "name": "剪辑报表",
              "path": "editingReports",
              "component": "./EditingReports/EditingReports"
          },
          {
              "name": "广告报表",
              "path": "adReport",
              "component": "./AdReport/AdReport"
          },
          {
              "name": "素材报表",
              "path": "materialReport",
              "component": "./MaterialReport/MaterialReport"
          }
      ]
  },
  {
      "name": "配置管理",
      "path": "configuration",
      "routes": [
          {
              "name": "人员配置",
              "path": "personnel",
              "component": "./Personnel/Personnel"
          },
          {
              "name": "账号配置",
              "path": "account",
              "component": "./Account/Account"
          },
          {
              "name": "定向出价",
              "path": "targetedBidding",
              "component": "./TargetedBidding/TargetedBidding"
          },
          {
              "name": "投放品牌",
              "path": "brandPlacement",
              "component": "./BrandPlacement/BrandPlacement"
          },
          {
              "name": "自动回复",
              "path": "autoresponder",
              "component": "./Autoresponder/Autoresponder"
          }
      ]
  },
  {
      "name": "系统日志",
      "path": "logManagement",
      "routes": [
          {
              "name": "操作日志",
              "path": "operationLog",
              "component": "./OperationLog/OperationLog"
          },
          {
              "name": "登录日志",
              "path": "loginLog",
              "component": "./LoginLog/LoginLog"
          }
      ]
  },
  {
      "name": "视频剪辑",
      "path": "montage",
      "routes": [
          {
              "name": "素材片段",
              "path": "footageClips",
              "component": "./FootageClips/FootageClips"
          },
          {
              "name": "水印管理",
              "path": "watermarkManagement",
              "component": "./watermarkManagement/watermarkManagement"
          },
          {
              "name": "脚本文案",
              "path": "copywritingScripts",
              "component": "./CopywritingScripts/CopywritingScripts"
          },
          {
              "name": "片段模版",
              "path": "clipsTemplate",
              "component": "./ClipsTemplate/ClipsTemplate"
          },
          {
              "name": "连山素材库",
              "path": "oceMaterialCenter",
              "component": "./OceMaterialCenter/OceMaterialCenter"
          },
          {
              "name": "素材案例",
              "path": "materialReview",
              "component": "./MaterialReview/MaterialReview"
          }
      ]
  },
  {
      "name": "批量投放",
      "path": "batchPromotion",
      "routes": [
          {
              "name": "批量模板",
              "path": "batchTemplate",
              "component": "./BatchTemplate/BatchTemplate"
          },
          {
              "name": "批量推广",
              "path": "automaticPlacement",
              "component": "./AutomaticPlacement/AutomaticPlacement"
          },
          {
              "name": "批量推广列表",
              "path": "batchList",
              "component": "./BatchList/BatchList"
          }
      ]
  },
  {
      "name": "策略投放",
      "path": "jobPromotion",
      "routes": [
          {
              "name": "我的策略",
              "path": "automatic2",
              "component": "./Automatic2/Automatic2"
          },
          {
              "name": "智美定向",
              "path": "zhimeiBidding",
              "component": "./ZhimeiBidding/ZhimeiBidding"
          },
          {
              "name": "策略模板",
              "path": "automaticTemplate2",
              "component": "./AutomaticTemplate2/AutomaticTemplate2"
          }
      ]
  },
  {
      "name": "海量投放",
      "path": "automaticPromotion",
      "routes": [
          {
              "name": "账户组",
              "path": "accountGroup",
              "component": "./AccountGroup/AccountGroup"
          },
          {
              "name": "批量定制",
              "path": "accountGroup2",
              "component": "./AccountGroup2/AccountGroup2"
          },
          {
              "name": "通用信息",
              "path": "categoryTemplate",
              "component": "./CategoryTemplate/CategoryTemplate"
          },
          {
              "name": "自动推广",
              "path": "automatic3",
              "component": "./Automatic3/Automatic3"
          }
      ]
  }
]

interface ServerMenu extends MenuDataItem {
  end_type: number;
  ico: string;
  is_permission: number;
  level: number;
  menu_desc: string;
  menu_id: number;
  menu_name: string;
  menu_url: string;
  parent_id: number;
  sort: number;
  spacer: string;
  status: number;
  type: number;
  path: string;
  name: string;
  meta: Meta;
  parent_path?:string;
  parent_name?:string;
  childlist: Partial<ServerMenu>[];
}
 

interface Meta {
  requiresAuth: boolean;
  icon: string;
  locale: string;
  order: number;
}


function createPath(serverMenu:Partial<ServerMenu>){

  // if(serverMenu.parent_name){
  //   return `${serverMenu.parent_path}/${serverMenu.path}`
  // }

  return `${serverMenu.path}`

}

function createName(serverMenu:Partial<ServerMenu>){

  if(serverMenu.parent_name){
    return `./${serverMenu.name}/${serverMenu.name}`
  }

  return `./${serverMenu.name}`

}

// 根据上面的 menuList变量生成适用于当前umi框架的router配置的函数
export function generateMenu(serverMenu:Partial<ServerMenu>):MenuDataItem{

  if(serverMenu.childlist && serverMenu.childlist.length>0){
    
     for(let i = 0 ;i < serverMenu.childlist.length;i++){
       serverMenu.childlist[i].parent_path = `${serverMenu.path}`
       serverMenu.childlist[i].parent_name = serverMenu.name
       serverMenu.childlist[i] = generateMenu(serverMenu.childlist[i])
     }
  }
  const route:MenuDataItem =  {
    name:  serverMenu.menu_name as string,
    path: createPath(serverMenu),
    icon: EditOutlined()
  }

  if(serverMenu.childlist && serverMenu.childlist.length>0){
    route['routes'] = serverMenu.childlist
  } else {
    route['component'] = createName(serverMenu)
  }


  return route

}

